package org.sherlock.downloader;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.sherlock.commons.download.FetcherException;
import org.sherlock.downloader.fetchers.Fetcher;
import org.sherlock.downloader.fetchers.FetcherFactory;

public class DownloadManager {
	private static final int CONCURRENT_DOWNLOADS = 5;
	
	private ArrayList<Download> downloads;
//	private DownloadsQueue queue;
	private ExecutorService executor;
	
	public DownloadManager() {
		this(CONCURRENT_DOWNLOADS);
	}
	
	public DownloadManager(int concurrentDownloads) {
		downloads = new ArrayList<Download>();
		
//		queue = new DownloadsQueue(concurrentDownloads);
		executor = Executors.newFixedThreadPool(2);
	}
	
	public void addDownload(Download download) throws FetcherException {
		downloads.add(download);
		
		Fetcher fetcher = FetcherFactory.getFetcher(download);
//		queue.execute(download);
		executor.execute(fetcher);
	}	
}
